package com.jh.concurrent.juc.condition;

import java.util.concurrent.TimeUnit;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title CustomQueueTest.java
 * @package com.jh.concurrent.juc.condition
 * @description 自制阻塞队列测试
 * @date 2019-05-21 10:57
 */
public class CustomQueueTest {

    public static void main(String[] args) throws InterruptedException {
        ReentConditionQueue<String> queue = new ReentConditionQueue<>(5);

        for (int i = 0; i < 10; i++) {
            int finalI = i;
            new Thread(() -> {
                queue.put(String.valueOf(finalI));
                System.out.println("当前线程：" + Thread.currentThread().getName()+ "_put：" + finalI);
            }, "Thread" + (finalI + 50)).start();
        }

        TimeUnit.SECONDS.sleep(5);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                System.out.println("当前线程：" + Thread.currentThread().getName()+ "_take：" + queue.take());
            }, "Thread" + i).start();
        }
    }

}
